package com.aqie.arithmetic.datastructure;

import com.aqie.libs.StdDraw;
import com.aqie.libs.StdOut;
import com.aqie.libs.StdRandom;

public class VisualAccumulator extends Accumulator {

    public VisualAccumulator(int trials, double max){
        StdDraw.setXscale(0, trials);
        StdDraw.setYscale(0, max);
        StdDraw.setPenRadius(.005);
    }

    public void addDataValue(double val){
      N++;
      total += val;
      StdDraw.setPenColor(StdDraw.DARK_GRAY);
      StdDraw.point(N, val);
      StdDraw.setPenColor(StdDraw.RED);
      StdDraw.point(N, total / N);
    }

    public static void main(String[] args) {
       int T = Integer.parseInt("1000");
       VisualAccumulator a = new VisualAccumulator(T, 1.0);
       for (int t = 0; t < T; t++){
           a.addDataValue(StdRandom.uniform());
       }
        StdOut.println(a);
    }
}
